package com.ahoi.common.base;

import com.ahoi.common.utils.ListUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Auther: ahoi
 * @Date: 2018/4/28 15:59
 * @Description:
 */
public enum ResponseCode {

    SUCCESS(200, "操作成功"),
    ERROR(500, "系统错误"),
    BIZERROR(500, "自定义错误"),
    NOLOGIN(401, "身份信息过期，请重新登录"),
    NOTFOUND(9001, "未找到相关数据"),;

    private int status;
    private String message;

    ResponseCode(int status, String message) {
        this.status = status;
        this.message = message;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public static String getMsgByStatus(int status) {
        String msg = null;
        List<ResponseCode> codes = Arrays.stream(ResponseCode.values()).filter(o -> o.getStatus() == status).collect(Collectors.toList());
        if (ListUtils.isNotEmpty(codes)) {
            msg = codes.get(0).message;
        }
        return msg;
    }
}
